<?php
/**
 * appRain v 0.1.x
 *
 * LICENSE
 *
 * This source file is subject to the MIT license that is bundled
 * with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.opensource.org/licenses/mit-license.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@apprain.com so we can send you a copy immediately.
 *
 * @copyright  Copyright (c) 2010 appRain, Team. (http://www.apprain.com)
 * @license    http://www.opensource.org/licenses/mit-license.php MIT license
 *
 * HELP
 *
 * Official Website
 * http://www.apprain.com/
 *
 * Download Link
 * http://www.apprain.com/download
 *
 * Documents Link
 * http ://www.apprain.com/docs
 */

$ext_class = isset( $file2editcontent ) ? 'displaynone"' :"";
echo $this->get_tag('div',array('id'=>'hidden_content','class'=>"$ext_class"));
    App::Helper('Toolbar')->setTitle("Code editor")->setBtnBack()->Render(array('code'=>'code_editor_top'));
    
    $pathback = substr($base_path,0,strrpos($base_path,'/'));
    $data[] = array(App::load("Helper/Html")->linkTag($this->baseurl('/developer/editor/' . base64_encode( $pathback )),'Back'),
    App::load("Helper/Html")->linkTag($this->baseurl('/developer/editor/' . base64_encode( $pathback )),App::load("Helper/Html")->imgTag($this->baseurl('/images/admin/back.gif'))));

    $Grid = App::Module('DataGrid');
    if( !empty($dir_listing['dir']))
    {
        foreach( $dir_listing['dir'] as $key => $val )
        {
            $name = $val["name"];
            $type = $val["type"];
            $Grid->addRow( ' <a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path . '/' . $name ) .  '">'. $name . '</a></label>',
                            ' <a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path . '/' . $name ) .  '"><img src="' . $this->baseurl('/') . '/images/admin/folder.gif" title="Enter" alt="Enter" /></a></label>'
                            );
        }
    }

    if( !empty($dir_listing['file']))
    {
        foreach( $dir_listing['file'] as $key => $val )
        {
            $base_path = ( $base_path != "") ? $base_path : "/";
            $name = $val["name"];
            $type = $val["type"];
            $Grid->addRow( '<label><a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path ) .  '/' . base64_encode($name) . '">' . $name .'</a></label>',
                            '<label><a href="' . $this->baseurl('/') . 'developer/editor/' . base64_encode( $base_path ) .  '/' . base64_encode($name) . '"><img src="' . $this->baseurl('/') . '/images/admin/edit.gif" title="Edit ' . $val['name'] .  '" alt="Edit" /></a></label>'
                            );
        }
    }

    if( !empty($data) )
    {
            $Grid->Render();
    }
    else
    {
        echo $this->callElement('common/message', array('caption' =>'Message','type' => 'error', 'message' => 'No Data found for Account'));
    }

    App::Helper('Toolbar')->setBtnBack()->Render(array('code'=>'code_editor_bottom'));
    
    echo '<br /><br />';
    echo $this->get_tag('/div');

    if( isset( $file2editcontent ) )
    {
        echo '<script type="text/javascript">
            window.addEvent("domready", function() {
                var myVerticalSlide = new Fx.Slide("hidden_content").show();
                $$(".view_hidden_content").addEvent("click", function(e){

                    e.stop();
                    $("hidden_content").setStyle("display", "block");
                    myVerticalSlide.toggle();
                });
            });
        </script>';
        echo $this->get_tag('form',array('class'=>'app_form','method'=>'post'));
            App::Helper('Toolbar')->setTitle($filepath)->setBtnToggle()->setBtnBack()->Render(array('code'=>'code_editor_edit_top'));
            
            if( $message ):
                echo $this->callElement('default/tools/message', array('caption' =>'Message','type' => 'error', 'message' => $message));
            endif;

            echo App::load("Helper/Html")->textareaTag("data[Editor][content]",htmlspecialchars($file2editcontent),array("class"=>"app_input","style"=>"width:99%","rows" => "30"));
            App::Helper('Toolbar')->setBtnSave()->setBtnBack()->Render(array('code'=>'code_editor_edit_bottom'));
        echo $this->get_tag("/form");
    }